import {
  Inject,
  Controller,
  Get,
  Param,
  Post,
  Query,
  Body,
  Del,
} from '@midwayjs/core';
import { TradeService } from '../service/trade.service';

@Controller('/trade')
export class TradeController {
  @Inject()
  tradeService: TradeService;

  /**
   * 新增一条交易
   */
  @Post('/add')
  async add(
    @Body()
    data: any
  ) {
    return {
      code: 0,
      msg: 'ok',
      data: await this.tradeService.add(data),
    };
  }

  /**
   * 查询所有交易记录
   */
  @Get('/list')
  async list() {
    return {
      code: 0,
      msg: 'ok',
      data: await this.tradeService.list(),
    };
  }

  /**
   * 查询详情
   */
  @Get('/info/:id')
  async info(
    @Param('id')
    id: number
  ) {
    return {
      code: 0,
      msg: 'ok',
      data: await this.tradeService.info(id),
    };
  }

  /**
   * 删除
   */
  @Del('/del')
  async del(
    @Query('id')
    id: number
  ) {
    return {
      code: 0,
      msg: 'ok',
      data: await this.tradeService.del(id),
    };
  }
}
